package threadPool;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/*
* 实现多线程的方式四：线程池
*
*
* */
public class ThreadPool_ implements Runnable  {

    @Override
    public void run() {
        for (int i = 0; i <100 ; i++) {
            if (i%2==0){
                System.out.println(i);
            }
        }
    }
}
class ThreadPoolTest{
    public static void main(String[] args) {
        ExecutorService service =  Executors.newFixedThreadPool(10); //创建大小为10的线程池
        ThreadPoolExecutor service1 = (ThreadPoolExecutor) service;
        service1.setCorePoolSize(15); //设置线程池大小

//        service1.setKeepAliveTime();
        service.execute(new ThreadPool_()); //适用于Runnable ,指定线程池里面的线程完成需要执行什么任务
//        service.submit() 使用于callable

        service.shutdown();  //关闭线程池

    }
}
